package com.docMan.quartz;

import org.apache.log4j.Logger;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

@Component("quartzIndexOA")
public class OaIndexQuartz implements InitializingBean  {
	 private Logger logger=Logger.getLogger(OaIndexQuartz.class);
	/*public static void main(String[] args) {
		try {
			Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
			scheduler.start();
			JobDetail job = JobBuilder.newJob(IndexOaJob.class).
					withIdentity("job1", "group1").build();*/
//			CronScheduleBuilder scheduleBuilder=CronScheduleBuilder.cronSchedule("*/10 * * * * ?");
		/*	Trigger trigger = TriggerBuilder
					.newTrigger()
					.withIdentity("job1", "group1")
					.withSchedule(scheduleBuilder).startNow().build();
			scheduler.scheduleJob(job, trigger);
		} catch (SchedulerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}*/
	


	@Override
	public void afterPropertiesSet() throws Exception {
		try {
			System.out.println("任务2222");
			logger.error("start quart renwu "+System.currentTimeMillis());
			Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
			scheduler.start();
			JobDetail job = JobBuilder.newJob(IndexOaJob.class).
					withIdentity("job1", "group1").build();
			
			CronScheduleBuilder scheduleBuilder=CronScheduleBuilder.cronSchedule("0 0 1 * * ?");
			Trigger trigger = TriggerBuilder
					.newTrigger()
					.withIdentity("job1", "group1")
					.withSchedule(scheduleBuilder).startNow().build();
			scheduler.scheduleJob(job, trigger);

		} catch (SchedulerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
